package org.lanqiao.utils;

import lombok.Data;

/**
 * 通用返回结果类
 * @param <T>
 */
@Data
public class Result<T> {
    //编码
    private Integer code;
    //错误信息
    private String msg;
    //数据
    private T data;

    public Result(){}

    //查询成功，不返回结果集（不需要显示查询到的结果）
    public static  Result success(Integer code , String msg){
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    //查询成功，显示结果集
    public static <T> Result<T> success(T data){
        Result result = new Result();
        result.setCode(1);
        result.setMsg("成功");
        result.setData(data);
        return result;
    }

    //查询失败，不返回结果集（不需要显示查询到的结果）
    public static  Result error(String msg){
        Result result = new Result();
        result.setCode(0);
        result.setMsg(msg);
        return result;
    }

}
